package com.dongdong.controller;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.C;
import com.dongdong.model.TbBrand;
import com.dongdong.result.PageBean;
import com.dongdong.result.PageResult;
import com.dongdong.result.Result;
import com.dongdong.result.ResultConstant;
import com.dongdong.service.BrandService;
import com.dongdong.vo.BrandVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@Controller
@RequestMapping("tbbrand")
public class BrandController {

    @Autowired
    private BrandService brandService;


    @GetMapping("findBrandAll")
        public Result findBrandAll(){
     List<BrandVO> brandVOS= brandService.getBrandAll();
        return new Result(ResultConstant.SUCCESS_CODE, ResultConstant.SUCCESS_MSG,brandVOS); //4：操作成功

    }
    //分页查询所有品牌信息带模糊查询
    @PostMapping("/findBrandPage")
    public Result findBrandPage(@RequestBody PageBean<BrandVO> pageBean){
        PageResult<BrandVO> result = brandService.findBrandPage(pageBean);

        return new Result(ResultConstant.SUCCESS_CODE, ResultConstant.SUCCESS_MSG,result); //4：操作成功
    }


    @PostMapping("add")
    public Result add(@RequestBody TbBrand tbBrand){
         brandService.insert(tbBrand);
        return new Result(ResultConstant.SUCCESS_CODE, ResultConstant.SUCCESS_MSG); //4：操作成功
    }

    @GetMapping("toupdate")
    public Result toupdate(@RequestParam Long id){
        BrandVO brandVO= brandService.selectbyid(id);
        return new Result(ResultConstant.SUCCESS_CODE, ResultConstant.SUCCESS_MSG,brandVO); //4：操作成功
    }
//修改
    @PutMapping("update")
    public Result update(@RequestBody TbBrand tbBrand){
        brandService.update(tbBrand);
        return new Result(ResultConstant.SUCCESS_CODE, ResultConstant.SUCCESS_MSG); //4：操作成功
    }

    @GetMapping("deletebyid")
    public Result deletebyid(@RequestParam Long id){
         brandService.deletebyid(id);
        return new Result(ResultConstant.SUCCESS_CODE, ResultConstant.SUCCESS_MSG); //4：操作成功
    }

}
